package com.deer.wms.busine.tactic.web;

import com.deer.wms.busine.tactic.model.Upper.UpperTactic;
import com.deer.wms.busine.tactic.model.Upper.UpperTacticCriteria;
import com.deer.wms.busine.tactic.model.Upper.UpperTacticDto;
import com.deer.wms.busine.tactic.service.UpperTacticService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;

import java.util.List;

/**
* Created by guo on 2019/11/28.
*/
@Api(description = "上架策略主表api接口")
@RestController
@RequestMapping("/upper/tactics")
public class UpperTacticController {

    @Autowired
    private UpperTacticService upperTacticService;

    @PostMapping("/insert")
    public Result add(@RequestBody UpperTactic upperTactic) {
        upperTacticService.save(upperTactic);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/delete")
    public Result delete(Integer id) {
        upperTacticService.removeById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody UpperTactic upperTactic) {
        upperTacticService.updateById(upperTactic);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/detail")
    public Result detail(Integer id) {
        UpperTactic upperTactic = upperTacticService.getById(id);
        return ResultGenerator.genSuccessResult(upperTactic);
    }

    @GetMapping("/list")
    public Result list(UpperTacticCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<UpperTacticDto> list = upperTacticService.findList(criteria);
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

}
